package com.campus.commons.entity;

import com.baomidou.mybatisplus.annotation.IdType;

import java.util.Collection;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import java.sql.Date;

import com.baomidou.mybatisplus.annotation.TableName;
import com.campus.app.mapper.Insert;
import com.campus.app.mapper.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="User对象", description="用户表")
@TableName(excludeProperty ={ "teacherId","teacherName","studentId","studentName","authorities"})

public class User implements Serializable, UserDetails {

    private static final long serialVersionUID = 1L;

    private Collection<? extends GrantedAuthority> authorities;

    public User(Integer id, Integer deid) {
        this.id = id;
        this.deid = deid;
    }

    public User(Integer id, String password, String phone) {
        this.id = id;
        this.password = password;
        this.phone = phone;
    }

    @Override
    public String getUsername() {
        return this.phone;
    }

    /**
     * 账号是否失效，返回false账号失效，不可用。
     *
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账号是否被锁，返回false，账号被锁，不可用
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 账号认证是否过期，返回false，过期，不可用
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 账号是否可用。返回false不可用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return state==0;
    }

    /**
     * 返回用户的权限集合。
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }
    //</editor-fold>


    @ApiModelProperty(value = "用户ID")
    @TableId(value = "id", type = IdType.AUTO)
    @NotNull(groups = Update.class)
    @Min(1)
    private Integer id;

    @ApiModelProperty(value = "用户名称")
    @NotNull(groups = Insert.class)
    @Length(groups = {Insert.class, Update.class},min = 1,max = 30)
    private String nickname;

    @ApiModelProperty(value = "用户密码")
    @NotNull(groups = Insert.class)
    @Length(groups = {Insert.class,Update.class},min = 6,max = 30)
    private String password;

    @ApiModelProperty(value = "向用户发送订阅信息的id")
    @TableField("openId")
    private String openid;

    @ApiModelProperty(value = "用户状态0.启用 1.禁用")
    @Range(max = 1,min = 0)
    private Integer state;

    @ApiModelProperty(value = "添加用户时间")
    @TableField("createTime")
    private Date createtime;

    @ApiModelProperty(value = "用户性别 0.男 1.女")
    @Range(max = 1,min = 0)
    private Integer gender;

    @ApiModelProperty(value = "出生日期")

    private Date birthday;

    @ApiModelProperty(value = "用户qq")
    private String qq;

    @ApiModelProperty(value = "手机账号")
    @NotBlank
    @Length(max = 11,min = 11,message = "请输入正确的手机号")
    private String phone;

    @ApiModelProperty(value = "用户签名")
    private String idiograph;

    @ApiModelProperty(value = "用户头像")
    @TableField("headIcon")
    private String headicon;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "部门id")
    @TableField("deId")
    private Integer deid;

    @ApiModelProperty(value = "角色id")
    @TableField("roleId")
    @Min(1)
    private Integer roleid;



    private Integer teacherId;
    private String teacherName;
    private Integer studentId;
    private String studentName;
}
